Convert clipboard page to JSON String and JSON String to clipboard page

Pega provides the below Functions:

    • @(Pega-RULES:Page).pxConvertStringToPage(tools, targetPage, data,"format")
    This function adopts input data as a string in a specified format (xml or json) onto the target clipboard page and returns a status indicating success or failure as a Boolean.
    Parameters
    • targetPage: Target clipboard page to map the input data to
    • data: Input data as a String
    • format: An optional format of input data, valid values are xml and json, default is json
    Return:
    • Boolean Value: true or false indicating success or failure of the operation
    • In case of error, 'errorMessage' param is set with an appropriate error message
    Example:

    We are going to see how to convert the below json string to a clipboard page.

    {
    "id":"555",
    "language":"C++",
    "edition":"second",
    "author":" Bjarne Stroustrup "
    }
    • Create and define a new page in clipboard using Page-New Method and define its class under Pages and Classes tab.
    • Define the data parameter to get the json string under Parameters tab.
    • Use Property-Set method to invoke the function pxConvertStringToPage by passing the parameters target Page, data and format (json) to convert the json string to a page in clipboard.
    • Run the activity by passing the json string in data parameter after the successful execution you can see the target Page is created in Clipboard with the values as per the above json string.
    • @(Pega-RULES:Page).pxConvertPageToString(tools, sourcePage, "format")
    This function is used to Convert input clipboard page into a string representation in the specified format.
    Parameters:
    • sourcePage: Source clipboard page to convert into a string representation
    • format: An optional output format of the string, valid values are xml and json, default value is json.
    Return:
    • String Value: String representation of clipboard page in the specified format
    • In case of error, 'errorMessage' param is set with an appropriate error message
    Example:

    We are going to see how to convert the below page in clipboard to the Json string in pega.


    • Use Property-Set method to invoke the function pxConvertPageToString by passing the parameters source Page and format (json) to convert the clipboard page to json string.
    • Run the activity after the successful execution you can see the source Page in Clipboard is converted to the json string which is set in result parameter and displayed by using Show-Page Method

    Happy Learning 😀!!!

    Popular Posts